﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.DirectShow;
using System.Windows.Media.DirectShow.Filters;
using System.Windows.Media.DirectShow.Ogg;
using System.Windows.Media.DirectShow.UI;

namespace Demo
{
    public partial class CapturePage : Page
    {

        private FilterGraph graph;
        private VideoAudioRenderer videoAudioRenderer;
        private ElementCaptureSource captureSource;

        public CapturePage()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            graph = new FilterGraph();

            captureSource = new ElementCaptureSource();
            graph.AddFilter("capture", captureSource);

            videoAudioRenderer = new VideoAudioRenderer();
            graph.AddFilter("render", videoAudioRenderer);

            graph.ConnectFilters(captureSource, videoAudioRenderer, MediaMajorTypes.Video);

            gv.SetGraph(graph, null);

            border.UpdateLayout();
            captureSource.SetElement(border, 12d);

            graph.RunAsync();
        }

        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            base.OnNavigatingFrom(e);

            graph.StopAsync();
        }

    }
}